Imports DotNetNuke
Imports DotNetNuke.Entities.Modules

Partial Class Compare
    Inherits PortalModuleBase
    Implements IActionable
    ' Methods
    Private Function BuildComparison(ByVal ProductGroupId As Integer) As StringBuilder
        Dim output As New StringBuilder
        Dim col_count As Integer = 0
        Dim temp_count As Integer = 0
        Dim list As New ArrayList
        Dim pc As New ProductController
        Dim fc As New FeatureController
        Dim fgc As New FeatureGroupController
        Dim fgi As New FeatureGroupInfo
        Try
            output.Append("<table class=""apc_productcomparison_table "" cellpadding=""0"" cellspacing=""0"">")
            Dim dr As IDataReader = pc.GetProductListByProductGroupId(ProductGroupId)
            output.Append("<tr class=""apc_product_row"">")
            output.Append("<td></td>")
            col_count += 1
            Do While dr.Read
                output.Append("<td class=""apc_product_cell"">")
                output.Append("<span class=""apc_product"">")
                output.Append(Convert.ToString(dr("Product")))
                output.Append("</span")
                output.Append("</td>")
                col_count += 1
            Loop
            output.Append("</tr>")
            dr.Close()
            dr = Nothing
            If (col_count <> 1) Then
                dr = fgc.GetFeatureGroupsByProductGroupId(ProductGroupId)
                Do While dr.Read
                    fgi.FeatureGroup = Convert.ToString(dr("FeatureGroup"))
                    fgi.FeatureGroupId = CInt(Convert.ToUInt32(dr("FeatureGroupId")))
                    fgi.SortOrder = CInt(Convert.ToUInt32((dr("SortOrder"))))
                    list.Insert((fgi.SortOrder - 1), fgi)
                    fgi = New FeatureGroupInfo
                Loop
                dr.Close()
                If (list.Count = 0) Then
                    output = New StringBuilder
                    output.Append(Services.Localization.Localization.GetString("NoFGs.Text", Me.LocalResourceFile))
                    Return output
                End If
                Dim i As Integer = 0
                Do While (i <= (list.Count - 1))
                    output.Append("<tr class=""apc_fg_row"">")
                    output.Append(("<td class=""apc_fg_cell"" colspan=""" & Convert.ToString(col_count) & """>"))
                    output.Append("<span class=""apc_fg"">")
                    output.Append(CType(list.Item(i), FeatureGroupInfo).FeatureGroup)
                    output.Append("</span>")
                    output.Append("</td>")
                    output.Append("</tr>")
                    dr = Nothing
                    dr = pc.GetProductFeatures(CType(list.Item(i), FeatureGroupInfo).FeatureGroupId)
                    temp_count = 1
                    Do While dr.Read
                        Dim alt_params As String
                        Dim pic_path As String
                        Dim js_params As String
                        If (temp_count = 1) Then
                            output.Append("<tr class=""apc_feature_row"">")
                            output.Append("<td class=""apc_feature_cell"">")
                            output.Append("<span class=""apc_feature"">")
                            output.Append(Convert.ToString((dr("Feature"))))
                            output.Append("</span> ")
                            If (Strings.Len(Convert.ToString((dr("Comment")))) > 0) Then
                                output.Append(String.Concat(New String() {"<div style=""display: inline;""><img id=""ac_", Convert.ToString((dr("FeatureId"))), """ onmouseover=""ac_togglePreview(this, ", Convert.ToString((dr("FeatureId"))), ")"" src=""", Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/about.gif"), """ /></div>"}))
                            End If
                            output.Append("</td>")
                        End If
                        Dim left As String = Convert.ToString((dr("SupportValue")))
                        If left.Equals("1") Then
                            pic_path = Me.Page.ResolveUrl("~/images/folderblank.GIF")
                            alt_params = Services.Localization.Localization.GetString("NA.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx"))
                            js_params = (Convert.ToString((dr("ProductId"))) & "|" & Convert.ToString((dr("FeatureId"))) & "|2")
                        ElseIf left.Equals("2") Then
                            pic_path = Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/unsupported.gif")
                            alt_params = Services.Localization.Localization.GetString("Unsupported.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx"))
                            js_params = (Convert.ToString((dr("ProductId"))) & "|" & Convert.ToString((dr("FeatureId"))) & "|3")
                        ElseIf left.Equals("3") Then
                            pic_path = Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/partial.gif")
                            alt_params = Services.Localization.Localization.GetString("PartialSupport.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx"))
                            js_params = (Convert.ToString(dr("ProductId")) & "|" & Convert.ToString(dr("FeatureId")) & "|4")
                        ElseIf left.Equals("4") Then
                            pic_path = Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/supported.gif")
                            alt_params = Services.Localization.Localization.GetString("Supported.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx"))
                            js_params = (Convert.ToString(dr("ProductId")) & "|" & Convert.ToString(dr("FeatureId")) & "|1")
                        ElseIf left.Equals("5") Then
                            pic_path = Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/note_add.png")
                            alt_params = Services.Localization.Localization.GetString("NoteAdd.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx"))
                            js_params = (Convert.ToString(dr("ProductId")) & "|" & Convert.ToString(dr("FeatureId")) & "|5")
                        Else
                            pic_path = Me.Page.ResolveUrl("~/images/folderblank.GIF")
                            alt_params = Services.Localization.Localization.GetString("NA.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx"))
                            js_params = (Convert.ToString((dr("ProductId"))) & "|" & Convert.ToString((dr("FeatureId"))) & "|2")
                        End If
                        output.Append("<td class=""apc_support_value_cell""><span class=""apc_support_value"">")
                        If left.Equals("5") Then
                            output.Append(String.Concat(Convert.ToString(dr("Text"))))
                        Else
                            output.Append(String.Concat(New String() {"<img alt=""", alt_params, """ src=""", pic_path, """></img>"}))
                        End If
                        output.Append("</span>")
                        output.Append("</td>")
                        temp_count += 1
                        If (temp_count = col_count) Then
                            output.Append("</tr>")
                            temp_count = 1
                        End If
                    Loop
                    dr.Close()
                    dr = Nothing
                    i += 1
                Loop
                If CBool(Me.Settings.Item("Pricing")) Then
                    dr = pc.GetProductListByProductGroupId(ProductGroupId)
                    output.Append("<tr class=""apc_pricing_row"">")
                    output.Append("<td class=""apc_price_head_cell""><span class=""apc_price_head"">" & Services.Localization.Localization.GetString("Pricing.Text", Me.LocalResourceFile) & "</span></td>")
                    Do While dr.Read
                        output.Append("<td class=""apc_price_cell"">")
                        output.Append("<span class=""apc_price"">")
                        If CBool(dr("DisplayPrice")) Then
                            output.Append(Services.Localization.Localization.GetString("Currency.Text", Services.Localization.Localization.GetResourceFile(Me, "ControlPanel.ascx.resx")) & Convert.ToDecimal((dr("Price"))).ToString("n"))
                        Else
                            output.Append("&nbsp;")
                        End If
                        output.Append("</span>")
                        output.Append("</td>")

                    Loop
                    output.Append("</tr>")
                    dr.Close()
                    dr.Dispose()
                End If
                With output
                    .Append("</table>")
                    .Append("<br />")
                    .Append("<table class=""apc_legend_table "" cellpadding=""0"" cellspacing=""0"">")
                    .Append("<tr class=""apc_legend_head_row""><td class=""apc_legend_head_cell""><span class=""apc_legend_head"">" & Services.Localization.Localization.GetString("Legend.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & "</span></td>")
                    .Append("<tr class=""apc_legend_row""><td class=""apc_legend_cell""><span class=""apc_legend"">")
                    .Append(("<img alt=""" & Services.Localization.Localization.GetString("FeatureComment.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/about.gif") & """></img> = " & Services.Localization.Localization.GetString("FCMessage.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & "<br />"))
                    .Append(("<img alt=""" & Services.Localization.Localization.GetString("Unsupported.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/unsupported.gif") & """></img> = " & Services.Localization.Localization.GetString("Unsupported.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & " <br />"))
                    .Append(("<img alt=""" & Services.Localization.Localization.GetString("PartialSupport.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/partial.gif") & """></img> = " & Services.Localization.Localization.GetString("PartialSupport.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & "<br />"))
                    .Append(("<img alt=""" & Services.Localization.Localization.GetString("Supported.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/supported.gif") & """></img> = " & Services.Localization.Localization.GetString("Supported.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")) & "<br />"))
                    .Append(Services.Localization.Localization.GetString("BlankNA.Text", Services.Localization.Localization.GetResourceFile(Me, "Legend.resx")))
                    .Append("</span></td></tr></table>")
                End With
                Return output
            End If
        Catch ex As Exception
            output = New StringBuilder
            output.Append(Services.Localization.Localization.GetString("Error.Text", Me.LocalResourceFile))
            Return output
        End Try
        output = New StringBuilder
        output.Append(Services.Localization.Localization.GetString("NoProducts.Text", Me.LocalResourceFile))
        Return output
    End Function


    ' Properties
    Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
        Get
            Dim actions As New Actions.ModuleActionCollection
            actions.Add(Me.GetNextActionID, Services.Localization.Localization.GetString("ControlPanel.Text", Me.LocalResourceFile), "AddContent.Action", "", "", Me.EditUrl, False, DotNetNuke.Security.SecurityAccessLevel.Edit, True, False)
            actions.Add(Me.GetNextActionID, Services.Localization.Localization.GetString("ManageComparison.Text", Me.LocalResourceFile), "AddContent.Action", "", "", Me.EditUrl("ManageComparison"), False, DotNetNuke.Security.SecurityAccessLevel.Edit, True, False)
            Return actions
        End Get
    End Property

    
    Public helperPath As String
    Public ImagePath As String
    Public PreviewText As String
    Public spinner As String

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Me.helperPath = Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/ACAjaxHelper.aspx")
            Me.spinner = Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/animated_loading.gif")
            Me.ImagePath = Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/delete.gif")
            Me.PreviewText = String.Empty
            Dim text As String = Convert.ToString(Me.Settings.Item("ProductGroupId"))
            Me.plhMain.Controls.Clear()
            If ((CInt(text) <= 0) Or (text Is Nothing)) Then
                Me.plhMain.Controls.Add(New LiteralControl(Services.Localization.Localization.GetString("DefaultMessage.Text", Me.LocalResourceFile)))
            Else
                Me.plhMain.Controls.Add(New LiteralControl(Me.BuildComparison(CInt(text)).ToString))
            End If

            imgClose.Src = ImagePath
            imgClose.Alt = Services.Localization.Localization.GetString("CloseFC.Text", Me.LocalResourceFile)

        Catch ex As Exception
            Me.plhMain.Controls.Add(New LiteralControl(Services.Localization.Localization.GetString("DefaultMessage.Text", Me.LocalResourceFile)))
        End Try
    End Sub
End Class